package com.xxzuibang.day9.封装;

public class AccountTest {
    public static void main(String[] args) {
//        Account account=new Account("小",1000,"1234567");
        Account account1=new Account();
        account1.setName("小");
        account1.setBalance(10000);
        account1.setPassword("1234567");
//        System.out.println("名称："+account.getName()+"余额："+account.getBalance()+"密码："+account.getPassword());
        System.out.println("名称："+account1.getName()+"余额："+account1.getBalance()+"密码："+account1.getPassword());
    }


}
class  Account{
    public String name;
    protected double balance;
    protected String password;

    public Account(String name, double balance, String password) {
        this.name = name;
        this.balance = balance;
        this.password = password;
    }

    public Account() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name.length()>=2&&name.length()<=4){
            this.name = name;
        }else{
            System.out.println("姓名长度不合规");
            this.name="无名氏";
        }

    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        if(balance>20){
            this.balance = balance;
        }else{
            System.out.println("余额连20都没有啊！");

        }

    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        if(password.length()==6){
            this.password = password;
        }else{
            System.out.println("密码长度不对哦~");
        }

    }

    @Override
    public String toString() {
        return "Account{" +
                "name='" + name + '\'' +
                ", balance=" + balance +
                ", password='" + password + '\'' +
                '}';
    }
}
